package rs.dalao.syc.doctor.all.dao.persist.repository.impl;

import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import rs.dalao.syc.doctor.all.dao.persist.mapper.ArticleMapper;
import rs.dalao.syc.doctor.all.dao.persist.repository.IArticleRepository;
import rs.dalao.syc.doctor.all.pojo.entity.Article;
import rs.dalao.syc.doctor.all.pojo.vo.ArticleManagementVO;
import rs.dalao.syc.doctor.all.pojo.vo.ArticleValidateVO;

import java.util.List;

@Slf4j
@Repository
public class ArticleRepositoryImpl implements IArticleRepository {

    @Autowired
    private ArticleMapper articleMapper;

    @Override
    public int insertArticle(Article Article){
        return articleMapper.insertArticle(Article);
    }

    @Override
    public int deleteArticleByArticleId(Long id) {
        log.debug("开始执行【根据ID删除文章】的数据访问，参数：{}", id);
        return articleMapper.deleteById(id);
    }

    @Override
    public Article getArticleById(Long id) {
        Article articleById = articleMapper.getArticleById(id);
        return articleById;
    }

    @Override
    public ArticleValidateVO getArticleByTitle(String title){
        return articleMapper.getArticleByTitle(title);
    }

    //通过作者Id获取当前作者发布的所有文章
    @Override
    public List<ArticleManagementVO> getAllArticleByAuthorId(Long authorId) {
        return articleMapper.getAllArticleByAuthorId(authorId);
    }

    @Override
    public int updateArticle(Article article) {
        //根据id修改文章
        return articleMapper.updateById(article);
    }


    //修改文章浏览量
    @Override
    public int updateViewCountById(Long id) {
        return articleMapper.updateViewCountById(id);
    }
}
